<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="账号">
        <el-input v-model="queryParams.mobile" placeholder="请输入用户账号" clearable @keyup.enter.native="getList" />
      </el-form-item>
      <el-form-item label="服务中心名称">
        <el-input v-model="queryParams.centerName" placeholder="请输入服务中心名称" clearable @keyup.enter.native="getList" />
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="queryParams.auditStatus" placeholder="请选择"  clearable >
          <el-option
            v-for="dict in statusList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRange"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList" >搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column label="用户账号" align="center" prop="mobile" min-width="120" />
      <el-table-column label="服务中心名称" align="center" prop="centerName" min-width="140" />
      <el-table-column label="申请金额" align="center" prop="money" min-width="120" />
      <el-table-column label="申请备注" align="center" prop="comment" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="100" />
      <el-table-column label="审批状态" align="center" prop="auditStatus">
        <template slot-scope="scope">
          <p>{{scope.row.auditStatus | getName(statusList)}}</p>
        </template>
      </el-table-column>
      <el-table-column label="审核备注" align="center" prop="auditRemark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-check" v-if="scope.row.auditStatus != 2 && scope.row.auditStatus != 3" @click="submit(scope.row,2)">通过</el-button> <br />
          <el-button size="mini" type="text" icon="el-icon-check" v-if="scope.row.auditStatus != 2 && scope.row.auditStatus != 3" @click="submit(scope.row,3)">拒绝</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <el-dialog title="拨款申请审核" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="用户账号" prop="mobile">
          <el-input v-model="form.mobile" disabled />
        </el-form-item>
        <el-form-item label="服务中心名称" prop="centerName">
          <el-input v-model="form.centerName" disabled />
        </el-form-item>
        <el-form-item label="申请金额" prop="money">
          <el-input v-model="form.money" disabled />
        </el-form-item>
        <el-form-item label="申请备注" prop="remark">
          <el-input v-model="form.comment" disabled />
        </el-form-item>
        <el-form-item label="审核状态" prop="auditStatus">
          <el-radio-group v-model="auditStatus">
            <el-radio :label="2">通过</el-radio>
            <el-radio :label="3">不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核备注" v-if="auditStatus === 3" >
          <el-input v-model="auditRemarks" type="textarea" :maxlength="50" placeholder="请输入审核备注"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { applyData ,applyDataList } from "@/api/serviceExamine/serviceExamine.js";
import { Debounce } from '@/utils/tools.js';
export default {
  name: "productCate",
  data() {
    return {
      // 1 待审核 2 审核通过 3 审核不通过
      statusList:[
        {label:'待审核',value: 1},
        {label:'通过',value: 2},
        {label:'不通过',value: 3},
      ],
      title: "新增服务中心用户",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      dataList: [],
      dataListLog: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openMoney:false,
      openLog:false,
      // 查询参数
      dateRange:'',
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        mobile: null,
        centerName: null,
        auditStatus: null,
        beginTime:null,
        endTime:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        auditRemarks: [
          { required: true, message: "请输入审核拒绝原因", trigger: "blur" },
        ],
      },
      activeName: 'first',
      totalMoney: null,
      totalCount: null,
      rolesBool: false,
      type: null,//区分审核是通过还是拒绝
      auditStatus:null,//审核
      auditRemarks: null,// 审核备注
    };
  },
  filters:{
    getName(val,statusList){
      let label;
      let arr = statusList.filter(item => item.value == val)
      if(arr.length){
        label = arr[0].label
      }
      return label;
    }
  },
  watch:{
    dateRange:{
      handler(val){
        if(val && val.length === 2){
          this.queryParams.beginTime = val[0]
          this.queryParams.endTime = val[1]
        }else{
          this.queryParams.beginTime = null
          this.queryParams.endTime = null
        }
      }
    }
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      applyDataList(this.queryParams).then((response) => {
        if(response.code == 200){
          this.dataList = response.data;
          this.total = response.extend.total;
          this.loading = false;
        }
      });
    },
    // 审核
    submitForm(){
      let that = this
      let txt = that.auditStatus == 2 ?'通过': '拒绝';
      if(that.auditStatus == 3 && !that.auditRemarks){
        that.$modal.msgWarning("请输入申请拒绝原因 !");
        return
      }
      that.$modal.confirm('是否确认'+txt+'该申请？').then(function() {
        let parmas = {
          id: that.form.id,
          auditStatus: that.auditStatus,
          auditRemark: that.auditRemarks,
        }
        applyData(parmas).then(res => {
          if(res.code === 200){
            that.$modal.msgSuccess("操作成功");
            that.open = false
            that.form = {}
            that.getList();
          }
        })
      })
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = null
      this.resetForm("queryForm");
      this.queryParams = {
        pageNo: 1,
        pageSize: 10,
        mobile: null,
        centerName: null,
        auditStatus: null,
        rangeTime:null,
        beginTime:null,
        endTime:null,
      };
      this.getList();
    },
    // 通过 | 拒绝
    submit(data,type){
      this.auditRemarks = null;
      this.auditStatus = type
      this.form = JSON.parse(JSON.stringify(data))
      this.open = true;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
  },
};
</script>
<style>
.m-t-5{
  margin-top: 5px;
}
.closeBtn{
  font-size: 24px;
  position: absolute;
  right: -2px;
  top: -2px;
}
.flex{
  display: flex;
}
.m-l-20{
  margin-left: 20px;
}
.blue{
  color: #409eff;
}
.imgBox{
  width: 100%;
  display: flex;
  flex-wrap: wrap;
}
.el-input.is-disabled .el-input__inner{
  color: #606266;
}
.minH{
  min-height: 400px;
}
</style>
